package org.arch_learn.spring_cloud.scn_homework.service_code_8081.endpoint;

import org.arch_learn.spring_cloud.scn_homework.service_code_8081.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

@RestController
@RequestMapping(value = "/code")
public class CodeEndpoint {
    @Autowired
    private ICodeService codeService;

    @PostMapping(value = "/create/{email}")
    public ResponseEntity<Boolean> createAndSendCode(@PathVariable String email) {
        Boolean result = codeService.createAndSendCode(email);
        return ResponseEntity.ok(result);
    }

    @GetMapping(value = "/validate/{email}/{code}")
    public ResponseEntity<Integer> validateCode(@PathVariable String email,
                                                @PathVariable @NotBlank String code) {
        Integer result = codeService.validateCode(email,code);
        return ResponseEntity.ok(result);
    }
}
